package com.vanguard.controller;

import com.vanguard.commons.base.BaseDomain;
import com.vanguard.commons.constant.CommonReturnCode;
import com.vanguard.commons.exception.BusinessException;
import com.vanguard.commons.pojo.ResponseResult;
import com.vanguard.commons.utils.LoggerUtils;
import com.vanguard.domain.User;
import com.vanguard.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: 用户前端控制器
 * @Description:
 * @Author: vanguard
 * @Version: 1.0
 * @Date: 2018/11/22
 */
@Controller
@RequestMapping("user")
public class UserController extends BaseDomain {

    @Autowired
    private IUserService userService;

    /**
     * 跳转到注册页面
     * 输入姓名和身份证号
     * @return
     */
    @GetMapping("/toRegister")
    public String register() {
        return "/register";
    }

    @PostMapping("/register")
    @ResponseBody
    public Object register(@RequestBody User user) {
        try {
            userService.register(user);
        } catch (BusinessException e) {
            LoggerUtils.error(UserController.class, e.getMessage());
            return new ResponseResult(e.getCode(), e.getMessage());
        }
        return new ResponseResult(CommonReturnCode.OK);
    }
}
